﻿using System;
using System.Globalization;

namespace RTools_NTS.Util
{
	public class FloatToken : Token
	{
		private NumberFormatInfo GetNumberFormatInfo()
		{
			if (this.numberFormatInfo == null)
			{
				this.numberFormatInfo = new NumberFormatInfo();
				this.numberFormatInfo.NumberDecimalSeparator = ".";
			}
			return this.numberFormatInfo;
		}

		public FloatToken(string s) : base(0)
		{
			try
			{
				this.obj = double.Parse(s, this.GetNumberFormatInfo());
			}
			catch (Exception)
			{
				this.obj = null;
			}
		}

		public FloatToken(float f) : base(0)
		{
			try
			{
				this.obj = (double)f;
			}
			catch (Exception)
			{
				this.obj = null;
			}
		}

		public FloatToken(double d) : base(0)
		{
			try
			{
				this.obj = d;
			}
			catch (Exception)
			{
				this.obj = null;
			}
		}

		public FloatToken(string s, int line) : base(line)
		{
			try
			{
				this.obj = double.Parse(s, this.GetNumberFormatInfo());
			}
			catch (Exception)
			{
				this.obj = null;
			}
		}

		public FloatToken(double f, int line) : base(line)
		{
			try
			{
				this.obj = f;
			}
			catch (Exception)
			{
				this.obj = null;
			}
		}

		public override string ToDebugString()
		{
			if (this.obj != null)
			{
return string.Format("FloatToken: {0:R}", (double)this.obj);
			}
return string.Format("FloatToken: null", new object[0]);
		}

		public override string ToString()
		{
			if (this.obj != null)
			{
				return string.Format("{0:R}", (double)this.obj);
			}
			return string.Format("null", new object[0]);
		}

		public override int GetHashCode()
		{
			return this.ToString().GetHashCode();
		}

		public override string StringValue
		{
			get
			{
				if (this.obj != null)
				{
					return string.Format(this.GetNumberFormatInfo(), "{0:R}", new object[]
					{
						(double)this.obj
					});
				}
				return string.Format("null", new object[0]);
			}
		}

		public override bool Equals(object other)
		{
			return other != null && base.GetType().Equals(other.GetType()) && this.obj != null && ((FloatToken)other).obj != null && ((double)this.obj).Equals((double)((FloatToken)other).Object);
		}

		private NumberFormatInfo numberFormatInfo;
	}
}
